Skip to content

Add stop and down commands - #1339

Open
mrvenv wants to merge 1 commit into
devcontainers:mainfrom
mrvenv:stop-and-down-commands
Open

mrvenv wants to merge 1 commit into
devcontainers:mainfrom
mrvenv:stop-and-down-commands

Conversation

@mrvenv

@mrvenv mrvenv commented Oct 22, 2026

Copy link
Copy Markdown

Add devcontainer stop and devcontainer down

The README listed stop and down as planned but unimplemented. This PR adds both commands.

Usage

devcontainer stop [--workspace-folder | --container-id | --id-label <name=value>]
devcontainer down [--workspace-folder | --container-id | --id-label <name=value>] [--remove-volumes]

  • stop stops the dev container. Running devcontainer up again restarts the same container.
  • down stops the dev container and removes it.
  • The container is found the same way exec finds it: via --container-id, --id-label, or --workspace-folder (plus optional --config). If none of these is given, --workspace-folder defaults to the current directory.
  • Also supports --docker-path, --docker-compose-path, --log-level and --log-format.

Behavior

  • Image / Dockerfile configs: stop runs docker stop <id>. down runs docker rm -f <id> through the existing removeContainer helper, which now takes an optional removeVolumes flag that adds -v.
  • Docker Compose configs (detected via the com.docker.compose.project label): the commands run docker compose -p <project> stop|down, so every service in the project is handled.
    • With Compose v1 (docker-compose), the Compose files are passed with -f, taken from the container's com.docker.compose.project.config_files label.
  • --remove-volumes (down only) removes anonymous volumes. For Compose configs it also removes named volumes declared in the Compose file (down -v).
  • No matching container: the command logs Dev container not found. and exits with success. This makes down safe to run more than once.
  • Output: on success, stdout gets a JSON line, consistent with the other commands:
    {"outcome":"success","containerId":"…","composeProjectName":"…"}

Changes

  • src/spec-node/devContainersSpecCLI.ts: adds the stop and down commands and their shared options.
  • src/spec-shutdown/dockerUtils.ts: removeContainer() takes an optional removeVolumes parameter (default false), so existing callers behave the same.
  • README.md: marks stop and down as done and adds them to the command list.
  • src/test/cli.stop-down.test.ts: new tests.

Tests

src/test/cli.stop-down.test.ts covers:

  • image config: stop followed by up reuses the same container
  • image config: down by --workspace-folder and by --container-id
  • image config: down when the container has already been removed
  • Compose config: stop and down for the whole project

`devcontainer stop` stops the dev container and `devcontainer down` stops
and removes it. The container is located via --container-id, --id-label,
or --workspace-folder (defaulting to the current directory), and Docker
Compose configurations are handled through the Compose project.
`down --remove-volumes` also removes anonymous volumes (and named volumes
declared in the Compose file for Compose configurations).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mrvenv
mrvenv requested a review from a team as a code owner October 22, 2026 14:30
@mrvenv

mrvenv commented Oct 22, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant